package com.ml.mall.mapper.order;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ml.mall.bean.res.dashboard.DashboardAdminRes;
import com.ml.mall.bean.res.dashboard.DashboardAppointDateOrderRes;
import com.ml.mall.bean.res.dashboard.DashboardRes;
import com.ml.mall.bean.res.dashboard.RecentOrderRes;
import com.ml.mall.bean.res.dashboard.vo.DashBoardNumByPurchaserVo;
import com.ml.mall.bean.res.dashboard.vo.DashBoardTopTenSpentCategoryVo;
import com.ml.mall.bean.res.dashboard.vo.DashBoardTopTenSpentSupplierVo;
import com.ml.mall.entity.company.SysCompany;
import com.ml.mall.entity.order.SysOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysOrderMapper extends BaseMapper<SysOrder> {


    //通过单号查询订单对应公司
    @Update("update sys_order set state = #{state} where oid = #{oid}")
    int updateOrderState(@Param("oid") Long oid,@Param("state") Integer state);

    //通过单号查询订单对应公司
    @Select("select * from sys_order where oid = #{oid}")
    SysOrder selectOrderByOid(@Param("oid") Long oid);

    /**
     * @description    :查询最近订单，固定查询10条
     * @author         :zxm
     * @date           :2021/5/24
    **/
    List<RecentOrderRes> selectRecentOrder();

    /**
     * @description    :查询指定年月日内的订单（每天的订单）
     * @author         :zxm
     * @date           :2021/5/25
    **/
    List<DashboardAppointDateOrderRes> sumAppointDateStrOrder(@Param("beginDateStr") String beginDateStr, @Param("endDateStr") String endDateStr);

    /**
     * @description    :查询总的订单数量
     * @author         :zxm
     * @date           :2021/5/25
    **/
    DashboardRes sumTotalOrder();

    /**
     * @description    :查询指定日期时间内的订单
     * @author         :zxm
     * @date           :2021/5/25
    **/
    DashboardAdminRes sumTotalAppointDateOrder(@Param("beginDateStr") String beginDateStr, @Param("endDateStr") String endDateStr);

    /**
     * @description    :查询买家最近的订单
     * @author         :zxm
     * @date           :2021/5/28
    **/
    List<RecentOrderRes> selectRecentOrderByPurchaser(@Param("purchaseId") Long companyId);

    /**
     * @description    :买家查询仪表盘数据统计
     * @author         :pl
     * @date           :2021/6/4
     **/
    DashBoardNumByPurchaserVo selectDashboardByPurchaser(@Param("purchaseId") Long companyId,@Param("timeBegin") String timeBegin,@Param("timeEnd") String timeEnd);

    /**
     * @description    :消费前十目录
     * @author         :pl
     * @date           :2021/6/4
     **/
    List<DashBoardTopTenSpentCategoryVo> selectTopTenSpentCategory(@Param("purchaseId") Long companyId,@Param("timeBegin") String timeBegin,@Param("timeEnd") String timeEnd);

    /**
     * @description    :消费前十对应的供货商
     * @author         :pl
     * @date           :2021/6/4
     **/
    List<DashBoardTopTenSpentSupplierVo> selectTopTenSpentSupplier(@Param("purchaseId") Long companyId,@Param("timeBegin") String timeBegin,@Param("timeEnd") String timeEnd);

    SysCompany selectOrderCompanyByOid(Long oid);
}
